home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VB / UNSUPPRT / VOICE / VCHATAPP / TCP_FUNC.BAS < prev    next >
Encoding:
BASIC Source File  |  1997-01-16  |  5.0 KB  |  92 lines

  1. Attribute VB_Name = "TCP_Functions"
  2. Option Explicit
  3. '------------------------------------------------------------
  4. Public Function InstanceTCP(TCPArray As Variant) As Long
  5. '------------------------------------------------------------
  6.     Dim Ind As Long                                 ' Array Index Var...
  7. '------------------------------------------------------------
  8.     InstanceTCP = -1                                ' Set Default Value
  9.     On Error GoTo InitControl                       ' IF Error Then Control Is Available
  10.     
  11.     For Ind = MINTCP To MAXTCP                      ' For Each Member In TCPArray() + 1
  12.         If (TCPArray(Ind).Name = "") Then           ' If Control Is Not Valid Then..
  13.         End If                                      ' ..A Runtime Error Will Occure
  14.     Next                                            ' Search Next Item In Array
  15. '------------------------------------------------------------
  16. InitControl:                                        ' Initialize New Control
  17. '------------------------------------------------------------
  18.     On Error GoTo ErrorHandler                      ' Enable Error Handling...
  19.             
  20.     If ((Ind >= MINTCP) And (Ind <= MAXTCP)) Then   ' Check to make sure index value is with in range
  21.         Load TCPArray(Ind)                          ' Create New Member In TCPArray
  22.         InstanceTCP = Ind                           ' Return New TCPctl Index
  23.     End If
  24.     
  25.     Exit Function                                   ' Exit
  26. '------------------------------------------------------------
  27. ErrorHandler:                                       ' Handler
  28. '------------------------------------------------------------
  29.     Debug.Print Err.Number, Err.Description         ' Debug Errors
  30.     Resume Next                                     ' Ignore Error And Continue
  31. '------------------------------------------------------------
  32. End Function
  33. '------------------------------------------------------------
  34.  
  35. '------------------------------------------------------------------
  36. Public Function Connect(Socket As Winsock, RemHost As String, RemPort As Long) As Boolean
  37. ' Attempts To Open A Socket Connection
  38. '------------------------------------------------------------------
  39.     Connect = False                             ' Set default return code
  40.     Call CloseListen(Socket)                    ' Stop Listening On LocalPort
  41.     Socket.LocalPort = 0                        ' Not necessary, but done just in case
  42.     Call Socket.Connect(RemHost, RemPort)       ' Connect To Server
  43.     
  44.     Do While ((Socket.State = sckConnecting) Or _
  45.               (Socket.State = sckConnectionPending) Or _
  46.               (Socket.State = sckResolvingHost) Or _
  47.               (Socket.State = sckHostResolved) Or _
  48.               (Socket.State = sckOpen))         ' Attempting To Connect...
  49.         DoEvents                                ' Post Events
  50.     Loop                                        ' Keep Waiting
  51.  
  52.     Connect = (Socket.State = sckConnected)     ' Did Socket Connect On Port...
  53. '------------------------------------------------------------------
  54. End Function
  55. '------------------------------------------------------------------
  56.  
  57. '------------------------------------------------------------------
  58. Public Function Listen(Socket As Winsock) As Long
  59. ' Starts Listening For A Remote Connection Request On The LocalPort ID
  60. '------------------------------------------------------------------
  61.     If (Socket.State <> sckListening) Then      ' Is Socket Already Listening
  62.         If (Socket.LocalPort = 0) Then          ' If local port is not initialized then...
  63.             Socket.LocalPort = VOICEPORT        ' Set standard application port
  64.         End If
  65.         Call Socket.Listen                      ' Listen On Local Port...
  66.     End If
  67. '------------------------------------------------------------------
  68. End Function
  69. '------------------------------------------------------------------
  70.  
  71. '------------------------------------------------------------------
  72. Public Function CloseListen(Socket As Winsock) As Long
  73. ' Stops Listening On A LocalPort For A Remote Connection Request...
  74. '------------------------------------------------------------------
  75.     If (Socket.State = sckListening) Then       ' Is Socket Listening?
  76.         Socket.Close                            ' Close Listen
  77.     End If
  78. '------------------------------------------------------------------
  79. End Function
  80. '------------------------------------------------------------------
  81.  
  82. '------------------------------------------------------------------
  83. Public Sub Disconnect(Socket As Winsock)
  84. ' Disconnects A Remote WinSock TCP/IP Connection If Connected
  85. '------------------------------------------------------------------
  86.     If (Socket.State <> sckClosed) Then         ' Is Socket Already Closed?
  87.         Socket.Close                            ' Close Socket
  88.     End If
  89. '------------------------------------------------------------------
  90. End Sub
  91. '------------------------------------------------------------------
  92.